package com.peace.hospital.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peace.hospital.entity.hospitalization.entity.Department;
import com.peace.hospital.entity.hospitalization.entity.Sckbed;
import com.peace.hospital.entity.hospitalization.entity.dto.InpatientmessageDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xie
 * @since 2019-11-12
 */
@Mapper
public interface SckbedMapper extends BaseMapper<Sckbed> {


    /**
     *  通过科室id查找空房间
     * @param d-科室id
     * @return
     */
    @Select({"SELECT * " +
            "FROM hospital_public.sckbed sc INNER JOIN hospital_public.sickroo si ON sc.sicid = si.sicid " +
            "INNER JOIN hospital_public.department de ON de.depid = si.depid " +
            "WHERE de.depid = #{depid} AND sckwhether = 0"})
    List<Sckbed> getAllEmptyBed(Department d);


    /**
     * 入住病房
     * @param i 入住信息对象
     * @return
     */
    @Update({"UPDATE hospitalization.sckbed" +
            "SET sckwhether = 1" +
            "WHERE sckid = #{i.sckid}"})
    int changeBedState(InpatientmessageDto i);
}
